package models;

import play.*;
import play.db.jpa.*;

import javax.persistence.*;

import java.util.*;

@Entity
public class Score extends Model {

	public long exerciseId;
	// this class to set the score of every exercise that user took
	public int score; // the score he got
	public long userId; // the user id

	// create array of scores that saves all the scores of the people who took
	// the quiz
	// private static ArrayList<Integer>allScores=new ArrayList<Integer>();
	// create array that saves the names of the people who took the quiz
	// private static ArrayList<Long>peopleID=new ArrayList<Long>();
	@ManyToMany 
	@JoinTable(name="uex")
	public List<RegisteredUser> userExerciseScores;

	public Score(long exerciseId, int score, long userId) {

		this.exerciseId = exerciseId;
		this.score = score;
		this.userId = userId;
		this.save();
		// To add Scores
		// allScores.add(s);
		// peopleID.add(userId);
	}

	// public int getScore() {
	// return score;
	// }
	//
	// public void setScore(int score) {
	// allScores.remove(this.score);
	// this.score = score;
	// allScores.add(score);
	// }
	//
	// public Long getUserId() {
	// return userId;
	// }
	//
	// public void setUserId(Long userId) {
	//
	// peopleID.remove(this.userId);
	// this.userId = (Long) userId;
	// peopleID.add(userId);
	// }
	//
	//
	//
	//
	// // Start Aya
	// /*
	// * Takes the user Id, array of score score of user
	// * compares the grades of people who took the quiz
	// * and then see the rank of the person who recomended to see his rank
	// * and return the rank
	// *
	// * @author Aya
	// *
	// * @param Score, all Scores [], people ID []
	// */
	//
	//
	// // method " as a user i can see my rank among the people who took the
	// quiz
	// // the Registered user will see his ranking among the people who took
	// this exercise before.
	//
	// public HashMap<Integer, Integer> ViewRank () {
	// //First we sort the array of Scores.
	// Collections.sort(allScores);
	// //I represent the Rank of Score.
	// int i=1;
	// HashMap<Integer,Integer> rankList=new HashMap<Integer, Integer>();
	//
	// for(Integer s:allScores){
	//
	// rankList.put(i, s);
	// }
	// return rankList;
	// }
	//
	// // Start Aya
	// /*
	// * Takes the user Id, array of score, score of user calculate the
	// percentage
	// * of the score of user
	// *
	// * @author Aya
	// *
	// * @param int s , all Scores [], people ID []
	// */
	//
	//
	// // method " as a user i can see my rank among the people who took the
	// quiz
	// //the Registered user will see a chart saying the percentage of people
	// who got grades from 100 to 80 and from 80 to 60 and so on and i will see
	// myself within these percentages
	//
	// public double ViewPercentage () {
	// int max=Collections.max(allScores);
	// return (100.0*score)/max;
	// }
	//
	// // end aya alaa
}